package com.rzjm.exercise.common.base.entity;


import java.io.Serializable;

import com.rzjm.exercise.common.utils.PersistableHelper;
import com.rzjm.exercise.sys.core.file.service.FileService;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;


/**
 * Entity支持类
 *
 * @param <T>
 */

public abstract class BaseEntity implements Serializable {

	private static final long serialVersionUID = 7031615749119508621L;
	
	/**
     * 实体编号（唯一标识）
     */
    protected Integer id;
    
    
    public String getTableName() {
		return PersistableHelper.getTableName(getClass());
	}
    
    public String getFilePrefix() {
		return PersistableHelper.getTableName(getClass()) + FileService.separator;
	}

    public BaseEntity() {

    }

    public BaseEntity(Integer id) {
        this();
        this.id = id;
    }
    
    @JsonSerialize(using = ToStringSerializer.class)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!getClass().equals(obj.getClass())) {
            return false;
        }
        BaseEntity that = (BaseEntity) obj;
        return null == this.getId() ? false : this.getId().equals(that.getId());
    }
}
